package com.yjd.job.order;

import com.alibaba.edas.schedulerX.ProcessResult;
import com.alibaba.edas.schedulerX.ScxSimpleJobContext;
import com.alibaba.edas.schedulerX.ScxSimpleJobProcessor;
import com.alibaba.fastjson.JSON;
import com.yjd.comm.fundservice.enums.FundChannelEnum;
import com.yjd.comm.repayment.dto.RepaymentOrderInfoDto;
import com.yjd.comm.repayment.service.IRepaymentDataService;
import com.yjd.comm.util.FrameUtil;
import org.apache.log4j.Logger;

import javax.annotation.Resource;
import java.util.List;

/**
 * 更新订单还款报表信息
 * Created by yjd-wap on 2018/3/16.
 */
public class OrderRepaymentUpdateJob implements ScxSimpleJobProcessor {

    Logger logger = Logger.getLogger(OrderRepaymentUpdateJob.class);
    @Override
    public ProcessResult process(ScxSimpleJobContext scxSimpleJobContext) {
        Long currTime = FrameUtil.getTime();
        List<RepaymentOrderInfoDto> list = null;
        try {
            list = repaymentDataService.getUpdateRepaymentOrderInfoList(FrameUtil.newHashMap("fund_channel", FundChannelEnum.QIAN_KANG.getValue(),"end_time",currTime));
            logger.info("开始更新还款表报,更新数据："+ JSON.toJSONString(list));
            if(list!=null&&list.size()>0){
                for(RepaymentOrderInfoDto orderInfo:list){
                    repaymentDataService.sendRepaymentByFundChannelMsg(orderInfo);
                }
            }
            logger.info("结束更新还款表报");

        } catch (Exception e) {
            logger.error("更新订单还款报表信息失败", e);
            return new ProcessResult(false);
        }
        return new ProcessResult(true);
    }

    @Resource
    private IRepaymentDataService repaymentDataService;
}
